package me.xue.communityhealth.service;

import me.xue.communityhealth.exception.ObjectNotFoundException;
import me.xue.communityhealth.model.DrugDepot;
import me.xue.communityhealth.repo.DrugDepotRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DrugDepotService implements BaseService<DrugDepot, Integer> {

    private final DrugDepotRepository drugDepotRepository;

    @Autowired
    public DrugDepotService(DrugDepotRepository drugDepotRepository) {
        this.drugDepotRepository = drugDepotRepository;
    }

    @Override
    public int save(DrugDepot drugDepot) {
        return drugDepotRepository.save(drugDepot);
    }

    @Override
    public int update(DrugDepot drugDepot) {
        return drugDepotRepository.update(drugDepot);
    }

    public DrugDepot findOne(Integer id) {
        DrugDepot drugDepot = drugDepotRepository.findOne(id);
        if (drugDepot == null) {
            throw new ObjectNotFoundException();
        }
        return drugDepot;
    }

    @Override
    public int delete(Integer which) {
        return drugDepotRepository.delete(which);
    }

    @Override
    public List<DrugDepot> findAll() {
        return drugDepotRepository.findAll();
    }
}
